import { createRouter, createWebHistory } from 'vue-router'
import type { RouteRecordRaw } from 'vue-router'
const Layout = () => import('@/layout/Layout.vue')
export const constantRouterMap: AppRouteRecordRaw[] = [
  {
    path: '/',
    meta: {
      hidden: false
    },
    redirect: "/home/index",
    name: "redirect"
  },
  {
    path: '/login',
    name: 'login',
    meta: {
      hidden: true,
      title: 'login',
      i18nKey: 'login.login'
    },
    component: () => import('../views/login/login.vue')
  },
  {
    path: '/404',
    name: '404',
    meta: {
      hidden: true,
      title: '404',
      i18nKey: '404'
    },
    component: () => import('../views/404/404.vue')
  },
]
export const asyncRouterMap: AppRouteRecordRaw[] = [
  {
    path: '/home',
    name: 'homeMenu',
    meta: {
      hidden: false,
      icon: "home",
      alwaysShow: false,
      i18nKey: 'router.workbench',
      title: '首页',
      noTagsView: false,
      affix: false,
      isLink: false,
      keepAlive: false,
      roles: ['admin', 'test']
    },
    component: Layout,
    redirect: "/home/index",
    children: [
      {
        path: '/home/index',
        name: 'home',
        component: () => import('../views/home/home.vue'),
        meta: {
          title: '首页',
          i18nKey: 'router.home',
          keepAlive: false,
          icon: "home",
          affix: true,
          isLink: false,
          alwaysShow: false,
          roles: ['admin', 'test']
        },
        children: [],
      }
    ],
  },
  {
    path: '/live2d',
    name: 'live2d',
    meta: {
      hidden: false,
      icon: "menu",
      alwaysShow: false,
      i18nKey: 'router.live2d',
      title: 'live2d',
      roles: ['admin']
    },
    component: Layout,
    redirect: "/live2d/index",
    children: [
      {
        path: '/live2d/index',
        name: 'live2dPage',
        component: () => import('../views/live2d/index.vue'),
        children: [],
        meta: {
          title: 'live2d',
          i18nKey: 'router.live2d',
          keepAlive: false,
          icon: "menu",
          affix: false,
          roles: ['admin']
        }
      }
    ],
  },
  {
    path: '/MultiLevelMenu',
    name: 'multiLeve',
    meta: {
      hidden: false,
      title: 'MultiLevelMenu',
      i18nKey: 'router.MultiLevelMenu',
      icon: 'menu',
      noTagsView: false,
      affix: false,
      keepAlive: false,
      alwaysShow: false,
      roles: ['admin', 'test']
    },
    component: Layout,
    children: [
      {
        path: '/MultiLevelMenu/SecondLevel',
        name: 'SecondLevel',
        component: () => import('../views/MultiLevelMenu/SecondLevel.vue'),
        children: [],
        meta: {
          hidden: false,
          title: 'SecondLevel',
          i18nKey: 'router.SecondLevel',
          icon: 'menu',
          orderNum: 0,
          noTagsView: false,
          affix: false,
          keepAlive: false,
          alwaysShow: false,
          roles: ['admin', 'test']
        }
      },
      {
        path: '/MultiLevelMenu/ThirdLevelMenu',
        name: 'ThirdLevelMenu',
        component: Layout,
        meta: {
          hidden: false,
          title: 'menu2',
          i18nKey: 'router.ThirdLevelMenu',
          orderNum: 0,
          noTagsView: false,
          affix: false,
          keepAlive: false,
          icon: 'menu',
          alwaysShow: false,
          roles: ['admin', 'test']
        },
        children: [
          {
            path: '/MultiLevelMenu/ThirdLevelMenu/ThirdLevelMenu3-1',
            name: 'ThirdLevelMenu3-1',
            component: () => import('../views/MultiLevelMenu/ThirdLevelMenu/ThirdLevelMenu3-1.vue'),
            children: [],
            meta: {
              hidden: false,
              title: 'ThirdLevelMenu3-1',
              i18nKey: 'router.ThirdLevelMenu3-1',
              orderNum: 0,
              noTagsView: false,
              affix: false,
              keepAlive: false,
              icon: 'menu',
              roles: ['admin', 'test']
            },
          },
          {
            path: '/MultiLevelMenu/ThirdLevelMenu/ThirdLevelMenu3-2',
            name: 'ThirdLevelMenu3-2',
            component: () => import('../views/MultiLevelMenu/ThirdLevelMenu/ThirdLevelMenu3-2.vue'),
            children: [],
            meta: {
              hidden: false,
              title: 'ThirdLevelMenu3-2',
              i18nKey: 'router.ThirdLevelMenu3-2',
              orderNum: 0,
              noTagsView: false,
              affix: false,
              keepAlive: false,
              icon: 'menu',
              roles: ['admin', 'test']
            },
          },
        ],
      },
    ],
  },
  // {
  //   path: '/about',
  //   name: 'about',
  //   meta: {
  //     hidden: false,
  //     title: '关于我们',
  //     isLink: true,
  //     i18nKey: 'router.about',
  //     icon: 'about',
  //     noTagsView: false,
  //     affix: false,
  //     roles: ['admin', 'test']
  //   },
  //   component: "#",
  //   children: [
  //     {
  //       path: 'https://gitee.com/juanmaoya/paraboy-admin',
  //       name: 'gitee',
  //       component: '#',
  //       children: [],
  //       meta: {
  //         title: 'gitee',
  //         i18nKey: 'router.gitee',
  //         keepAlive: false,
  //         isLink: true,
  //         hidden: false,
  //         icon: 'gitee',
  //         noTagsView: false,
  //         affix: false,
  //         roles: ['admin', 'test']
  //       }
  //     },
  //     {
  //       path: 'https://github.com/',
  //       name: 'github',
  //       component: '#',
  //       children: [],
  //       meta: {
  //         alwaysShow: false,
  //         title: 'github',
  //         i18nKey: 'router.github',
  //         keepAlive: false,
  //         isLink: true,
  //         hidden: false,
  //         icon: 'github',
  //         noTagsView: false,
  //         affix: false,
  //         roles: ['admin', 'test']
  //       }
  //     },
  //   ],
  // },
  {
    path: '/manage',
    name: 'manage',
    meta: {
      hidden: false,
      title: '系统管理',
      icon: "menu",
      alwaysShow: true,
      i18nKey: 'router.manage',
      noTagsView: false,
      affix: false,
      isLink: false,
      keepAlive: false,
      roles: ['admin']
    },
    component: Layout,
    redirect: "/manage/menu",
    children: [
      {
        path: '/manage/menu',
        name: 'menu',
        component: () => import('../views/manage/menu/menu.vue'),
        children: [],
        meta: {
          title: '菜单管理',
          i18nKey: 'router.manage_menu',
          keepAlive: false,
          icon: "menuSetting",
          affix: false,
          noTagsView: false,
          isLink: false,
          alwaysShow: false,
          hidden: false,
          roles: ['admin']
        }
      },
      {
        path: '/manage/roles',
        name: 'roles',
        component: () => import('../views/manage/roles/roles.vue'),
        children: [],
        meta: {
          title: '角色管理',
          i18nKey: 'router.manage_roles',
          keepAlive: false,
          icon: "roles",
          affix: false,
          noTagsView: false,
          isLink: false,
          alwaysShow: false,
          hidden: false,
          roles: ['admin']
        }
      },
      {
        path: '/manage/user',
        name: 'user',
        component: () => import('../views/manage/user/user.vue'),
        children: [],
        meta: {
          title: '用户管理',
          i18nKey: 'router.manage_user',
          keepAlive: false,
          icon: "manageUser",
          affix: false,
          noTagsView: false,
          isLink: false,
          alwaysShow: false,
          hidden: false,
          roles: ['admin']
        }
      },
    ],
  },
  {
    path: '/about',
    name: 'about',
    meta: {
      hidden: false,
      title: '系统管理',
      icon: "about",
      alwaysShow: false,
      i18nKey: 'router.about',
      noTagsView: false,
      affix: false,
      isLink: false,
      keepAlive: false,
      roles: ['admin']
    },
    component: Layout,
    redirect: "/about/index",
    children: [
      {
        path: '/about/index',
        name: 'aboutInfo',
        component: () => import('../views/about/index.vue'),
        children: [],
        meta: {
          title: '菜单管理',
          i18nKey: 'router.about',
          keepAlive: false,
          icon: "about",
          affix: false,
          noTagsView: false,
          isLink: false,
          alwaysShow: false,
          hidden: false,
          roles: ['admin']
        }
      }
    ],
  },
]
const router = createRouter({
  history: createWebHistory(import.meta.env.BASE_URL),
  routes: constantRouterMap as RouteRecordRaw[]
})
export const resetRouter = (): void => {
  const resetWhiteNameList = ['login', 'redirect', '/', '/404']
  router.getRoutes().forEach((route) => {
    const { name } = route
    if (name && !resetWhiteNameList.includes(name as string)) {
      router.hasRoute(name) && router.removeRoute(name)
    }
  })
}
export default router
